#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :api_02.py
# @Time      :2024/11/9 0:44
# @Author    :zhou_yi

from fastapi import APIRouter, UploadFile, File
from service.fn_file import save_word_tpl_file_to_storage, handle_excel_data_file, get_word_tpl_files

a04 = APIRouter()


# 查看相关联的word模板文件
@a04.get('/word_tpl_files/{key}', summary='返回work模板文件')
def word_tpl_files(key: str) -> list[dict]:
    _res: list[dict] = get_word_tpl_files(key, filemode='*.docx')
    return _res


# 模版文件上传
@a04.post('/word_tpl_file')
async def upload_word_tpl_file(file: UploadFile = File(...)) -> bool:
    b = await file.read()
    _res: bool = save_word_tpl_file_to_storage(b, file.filename)
    return _res


# 上传excel 读取数据,存入数据库相应集合中...
@a04.post('/excle_data_file/{sheetName}')
async def upload_excel_data_file(sheetName: str, file: UploadFile = File(...)) -> bool:
    b = await file.read()
    _res: bool = handle_excel_data_file(b, sheetName)
    return _res

# # 点位图片上传并保存到文件数据库上
# @a04.post('/point_image/{point}')
# async def upload_point_image(point: str, img: UploadFile = File(...)):
#     b: bytes = await img.read()
#     _res = await addressDB.fetch_by_point(point=point)
#     _id = _res['_id']
#     name = f"{_id}.png"
#
#     _res = await img_save_to_Gfs_point(b, name)
#     return list(_res)  # 文件id与文件名


# # 获取点位图片
# @a04.get('/point_image/{point}')
# async def get_poit_image(point: str):
#     _res = await addressDB.fetch_by_point(point)
#     _id = _res['_id']
#     _filename = f"{_id}.png"  # 数据库中的文件名
#     _bs64 = await img_get_from_Gfs_point_by_name(_filename)
#     return {'name': point, 'content': _bs64}


# # 清运记录图片上传，保存在数据库中
# @a04.post('/cwrs_image')
# def upload_cwrs_image():
#     ...
#
#
# # 获取清运记录图片
# @a04.get('/cwrs_image')
# def get_cwrs_image():
#     ...
